<?php
/**
 * @package   auto_occasion
 * @subpackage 
 * @author    CMS
 * @copyright 2011
 * @license    All rights reserved
 */


/**
 * Classe permettant de gerer les actus
 *actus
 */
class actuSrv {

    /**
     * Fonction permettant d'avoir la liste des actus
     * @param int $_idCat id d'une catégorie
     * @return object $liste
     *
     */
    public function listeByCategorie ($_idCat) {

        // instanciation de la factory
        $maFactory = jDao::get("commun~ao_actu");
        $records   = $maFactory->getListByCategorie($_idCat);

        return $records->fetchAll();
    }
    

    /**
     * Fonction permettant d'ajouter une actualité
     * @param object $actu
     *
     */
    public function ajouter ($actu) {
        // instanciation de la factory
        $maFactory = jDao::get("commun~ao_actu");
        $records   = jDao::createRecord("commun~ao_actu");

        $records->ao_actu_name         = $actu->ao_actu_name;
        $records->ao_actu_content      = $actu->ao_actu_content;
        $records->ao_actu_mot_cle_id   = $actu->ao_actu_mot_cle_id;
        $records->ao_actu_date         = $actu->ao_actu_date;
        $records->ao_actu_bon_plan     = $actu->ao_actu_bon_plan;
        $records->ao_actu_photo_1      = $actu->ao_actu_photo_1;
        $records->ao_actu_photo_2      = $actu->ao_actu_photo_2;
        $records->ao_actu_photo_3      = $actu->ao_actu_photo_3;
        $records->ao_actu_categorie_id = $actu->ao_actu_categorie_id;
        $records->ao_actu_priority     = $actu->ao_actu_priority;


        return $maFactory->insert($records);

    }
    
   
    /**
     * Fonction permettant de modifier une actualité
     * @param object $actu
     *
     */
    public function modifier ($actu) {

        // instanciation de la factory
        $maFactory = jDao::get("commun~ao_actu");
        $records   = $maFactory->get($actu->id);

        $records->ao_actu_name         = $actu->ao_actu_name;
        $records->ao_actu_content      = $actu->ao_actu_content;
        $records->ao_actu_mot_cle_id   = $actu->ao_actu_mot_cle_id;
        $records->ao_actu_date         = $actu->ao_actu_date;
        $records->ao_actu_bon_plan     = $actu->ao_actu_bon_plan;
        $records->ao_actu_photo_1      = (!$actu->ao_actu_photo_1)? $records->ao_actu_photo_1 : $actu->ao_actu_photo_1;
        $records->ao_actu_photo_2      = (!$actu->ao_actu_photo_2)? $records->ao_actu_photo_2 : $actu->ao_actu_photo_2;
        $records->ao_actu_photo_3      = (!$actu->ao_actu_photo_3)? $records->ao_actu_photo_3 : $actu->ao_actu_photo_3;
        $records->ao_actu_categorie_id = $actu->ao_actu_categorie_id;
        $records->ao_actu_priority     = $actu->ao_actu_priority;

        return $maFactory->update($records);

    }

    /**
     * Fonction permettant d'avoir une actu à partir de son id
     * @param $id
     * @return object
     *
     */
    public function chargeParId ($id) {
        $maFactory = jDao::get("commun~ao_actu");

        return $maFactory->get($id);

    }

    /**
     * Fonction permettant de supprimer une actu
     * @param $id
     * @return object
     *
     */
    public function supprimer ($id) {
        $maFactory = jDao::get("commun~ao_actu");

        return  $maFactory->delete($id);
    }

    /**
     * Fonction permettant d'initialiser un objet actu
     * @return object
     *
     */
    public function init () {

        $actu =  jDao::createRecord("commun~ao_actu");

        return $actu;
    }

   

}